# encoding: utf-8

import xlrd
import pytest
from common import get_project_path


def get_excel_data(filename, sheet_name):
    project_path = get_project_path.get_project_path()  # 调用函数，获取当前项目根目录
    file_path = project_path + '\\data\\test_data\\business_PC\\' + filename  # 读取的excel文件路径
    lst_data = []
    work_book = xlrd.open_workbook(file_path)
    work_sheet = work_book.sheet_by_name(sheet_name)
    rows = work_sheet.nrows
    cols = work_sheet.ncols
    for row in range(1, rows):  # 遍历时不取第一行表头内容
        row_list = []
        for col in range(cols):
            # ctype = work_sheet.cell(row, col).ctype  # 表格的数据类型
            # print(ctype)
            cell_data = work_sheet.cell_value(row, col)
            row_list.append(cell_data)  # 每一行的内容都放到一个列表中
        lst_data.append(row_list)  # 把多行内容放到同一个列表中
    return lst_data


filename = 'qiuxingka1.xlsx'
data = get_excel_data(filename, "login")
data1 = get_excel_data(filename, "group")


@pytest.mark.parametrize('user,password,expected', data)
def test_excel(user, password,expected):
    print(user, password, expected)


@pytest.mark.parametrize('season,sport,factory,series', data1)
def test_excel1(season,sport,factory,series):
    print(season,sport,factory,series)


if __name__ == '__main__':
    # print(get_excel_data())
    pytest.main(['-vs', 'read_excel.py'])